Homepage
The formatted source code for this file is here.
And a raw version here.
Previous work by Youngser Park can be found here.

We now have the following data sets:

1 Kernel Density Estimates of the marginals

df1 <- melt(as.matrix(fs))
names(df1) <- c("ind","channel","value")
df1$type <- factor(rep(ffchannel,each=dim(fs)[1]),levels=levels(ffchannel))

lvo <- c(1:5,7:10,19,22,11:16,6,17,18,20,21,23,24)
levels(df1$channel)<-levels(df1$channel)[lvo]

ts <- 22

gg1 <- ggplot(df1, aes(x=value)) + 
    scale_color_manual(values=ccol[lvo]) +
    scale_fill_manual(values=ccol[lvo]) +
    geom_histogram(aes(y=..density..,group=channel,colour=channel),bins=100) +
    geom_density(aes(group=channel, color=channel),size=1.5) +
    facet_wrap( ~ channel, scale='free', ncol=6) +
    theme(plot.title=element_text(size=ts),
          axis.title.x=element_text(size=ts),
          axis.title.y=element_text(size=ts),
          legend.title=element_text(size=ts),
          legend.text=element_text(size=ts-2),
          axis.text=element_text(size=ts-2),
          strip.text=element_text(size=ts), 
          legend.position='none')+
    ggtitle("Kernel Density Estimates of `fs` data.")

print(gg1)
Figure 1: Kernel density estimates for each channel, on fs data.

2 Correlations

cmatfs <- cor(fs)
corrplot(cmatfs,method="color",tl.col=ccol[ford], tl.cex=1)
Figure 2: Correlation on untransformed F0 data, reordered by synapse type.

3 Level 0

dat <- fs

3.1 Heat maps (Lv 0):

## Formatting data for heatmap
aggp <- apply(dat, 2, mean)
aggp <- t(cbind(aggp, aggp))

The following are heatmaps generated from clustering via K-means++ (at level 1)

heatmap.2(as.matrix(aggp),dendrogram='row',Colv=NA,trace="none", col=mycol,colCol=ccol[ford],cexRow=0.8, keysize=1.25,symkey=FALSE,symbreaks=FALSE,scale="none", srtCol=90,main="Heatmap of `fs` data.") 
#  [1] "#197300"    "#197300"    "#197300"    "#197300"    "#197300"   
#  [6] "#5ed155"    "#5ed155"    "#5ed155"    "#5ed155"    "#5ed155"   
# [11] "#5ed155"    "#660000"    "#660000"    "#660000"    "#cc0000"   
# [16] "#cc0000"    "#cc0000"    "#ff9933"    "#ff9933"    "mediumblue"
# [21] "mediumblue" "mediumblue" "gold"       "gold"
Figure 3: Heatmap of the cluster means vs channels. Rows and columns are rearranged according to synapse type.

Percentage of data within cluster is presented on the right side of the heatmap.

3.2 Jittered scatter plot: Lv 0

ggJdat <- stack(dat)
ggD <- data.table(ggJdat)

set.seed(1024)
tmp <- ggD[ sample(dim(ggD)[1], 1e4),]
tmp$ind <- as.factor(tmp$ind)
levels(tmp$ind) <- names(feat)[seq(1,144,by=6)][ford]

ggJ0 <- 
  ggplot(data = tmp, aes(x = ind, y = values)) +
  geom_point(alpha=0.75) + 
  geom_jitter(width = 1) + 
  theme(axis.title.x = element_blank()) + 
  theme(axis.text.x = element_text(color = ccol[ford], 
                                   angle=45,
                                   vjust = 0.5))
print(ggJ0)
Figure 4: Scatter Plot Level 0

4 Level 1: K-means++ for \(K=2\).

We run a Hierachical K-means++ for \(K=2\) on the fs data with 4 levels.

set.seed(2^13)
L <- bhkmpp(dat,blevels=4)

4.1 Heat maps (Lv 1):

## Formatting data for heatmap
aggp <- aggregate(dat,by=list(lab=L[[1]]),FUN=mean)
aggp <- as.matrix(aggp[,-1])
rownames(aggp) <- clusterFraction(L[[1]])

The following are heatmaps generated from clustering via K-means++ (at level 1)

heatmap.2(as.matrix(aggp),dendrogram='row',Colv=NA,trace="none", col=mycol,colCol=ccol[ford],cexRow=0.8, keysize=1.25,symkey=FALSE,symbreaks=FALSE,scale="none", srtCol=90,main="Heatmap of `fs` data.") 
#  [1] "#197300"    "#197300"    "#197300"    "#197300"    "#197300"   
#  [6] "#5ed155"    "#5ed155"    "#5ed155"    "#5ed155"    "#5ed155"   
# [11] "#5ed155"    "#660000"    "#660000"    "#660000"    "#cc0000"   
# [16] "#cc0000"    "#cc0000"    "#ff9933"    "#ff9933"    "mediumblue"
# [21] "mediumblue" "mediumblue" "gold"       "gold"
Figure 5: Heatmap of the cluster means vs channels. Rows and columns are rearranged according to synapse type.

Percentage of data within cluster is presented on the right side of the heatmap.

4.2 Jittered scatter plot: Lv 1

ggJdat <- stack(dat)
ggD <- data.table(ggJdat)
ggD$label <- L[[1]]

ggCol <- brewer.pal(4,"Set1")[order(table(L[[1]]))]

set.seed(1024)
tmp <- ggD[ sample(dim(ggD)[1], 1e4),]
tmp$label <- as.factor(tmp$lab)
tmp$ind <- as.factor(tmp$ind)
levels(tmp$ind) <- names(feat)[seq(1,144,by=6)][ford]

ggJ1 <- 
  ggplot(data = tmp, aes(x = ind, y = values, 
                         color = label, 
                         shape = label)) +
  scale_color_manual(values=ggCol) + 
  geom_point(alpha=0.75) + 
  geom_jitter(width = 1) + 
  theme(axis.title.x = element_blank()) + 
  theme(axis.text.x = element_text(color = ccol[ford], 
                                   angle=45,
                                   vjust = 0.5))
print(ggJ1)
Figure 6: Scatter Plot Level 1

4.3 Within cluster correlations (Lv 1)

corkp1 <- cor(dat[L[[1]] == 1,])
corkp2 <- cor(dat[L[[1]] == 2,])

par(mfrow=c(2,2))
corrplot(corkp1,method="color",tl.col=ccol[ford], tl.cex=0.8)
corrplot(corkp2,method="color",tl.col=ccol[ford], tl.cex=0.8)
corrplot(sqrt((corkp1 - corkp2)^2),is.corr=FALSE,method="color",tl.col=ccol[ford], tl.cex=0.8)
Figure 7: Within cluster correlations, clock-wise from top left, Cluster 1, Cluster 2, l2 distance between C1 and C2

Notice that the non-synaptic markers change very little between clusters. Also note that the correlations between (gad, VGAT, PV, Gephyr) and VGlut1 at both times change significantly between clusters.

4.4 Kernel Density Estimates of the marginals | cluster (Lv 1)

Here we look at the kernel density estimates within each cluster to compare.

df2 <- melt(as.matrix(dat))
names(df2) <- c("ind","channel","value")
df2$cluster <- L[[1]]
df2$type <- factor(rep(ffchannel,each=dim(dat)[1]),levels=levels(ffchannel))

gg2 <- ggplot(df2, aes(x=value)) + 
scale_colour_manual(values=ccol) + 
scale_x_continuous(limits=c(0,400)) +
geom_histogram(aes(y=..density..,group=channel,colour=channel),bins=250) +
geom_density(aes(group=channel, color=channel),size=1.5) +
facet_grid(channel ~ cluster, scale='free') + 
theme(strip.text.y=element_text(angle=0)) +
theme(strip.text.y   =element_text(angle=0),
      plot.title     =element_text(size=ts),
      axis.title.x   =element_text(size=ts),
      axis.title.y   =element_text(size=ts),
      legend.title   =element_text(size=ts),
      legend.text    =element_text(size=ts-2),
      strip.text     =element_text(size=ts), 
      legend.position='none')
print(gg2)
Figure 8: Kernel density estimates for each channel, on fs data given cluster from km++ level 1

4.5 Clusters and Spatial Location (Lv 1)

Using the location data and the results of K-means++ we show a 3d scatter plot colored accoding to cluster.

set.seed(2^12)
s1 <- sample(dim(loc)[1],5e4)

locs1 <- loc[s1,]
locs1$cluster <- L[[1]][s1]

plot3d(locs1$V1,locs1$V2,locs1$V3,
       col=brewer.pal(4,"Set1")[order(table(L[[1]]))][locs1$cluster],
       alpha=0.75,
       xlab='x', 
       ylab='y', 
       zlab='z')

subid <- currentSubscene3d()
rglwidget(elementId="plot3dLocations", height=720, width=720)

5 Level 2: K-means++ for \(K=2\).

5.1 Within cluster correlations (Lv 2)

corLV2 <- lapply(c(1:4),function(x){cor(dat[L[[2]] == x,])})

par(mfrow=c(2,2))
for(pl in corLV2){
corrplot(pl,method="color",tl.col=ccol[ford], tl.cex=0.8)
}
Figure 9: Within cluster correlations for level 2. (c11, c12, c21, c22)

5.2 Heat maps (Lv 2):

## Formatting data for heatmap
aggp2 <- aggregate(dat,by=list(lab=L[[2]]),FUN=function(x){mean(x)}) 
aggp2 <- as.matrix(aggp2[,-1])
rownames(aggp2) <- clusterFraction(L[[2]])

The following are heatmaps generated from clustering via K-means++

heatmap.2(as.matrix(aggp2),dendrogram='row',Colv=NA,trace="none", col=mycol,colCol=ccol[ford],cexRow=0.8, keysize=1.25,symkey=FALSE,symbreaks=FALSE,scale="none", srtCol=90,main="Heatmap of `fs` data.") 
#  [1] "#197300"    "#197300"    "#197300"    "#197300"    "#197300"   
#  [6] "#5ed155"    "#5ed155"    "#5ed155"    "#5ed155"    "#5ed155"   
# [11] "#5ed155"    "#660000"    "#660000"    "#660000"    "#cc0000"   
# [16] "#cc0000"    "#cc0000"    "#ff9933"    "#ff9933"    "mediumblue"
# [21] "mediumblue" "mediumblue" "gold"       "gold"
Figure 10: Heatmap of the cluster means vs channels. Rows and columns are rearranged according to synapse type.

Percentage of data within cluster is presented on the right side of the heatmap.

5.3 Kernel Density Estimates of the marginals | cluster (Lv 2)

Here we look at the kernel density estimates within each cluster to compare.

df2 <- melt(as.matrix(dat))
names(df2) <- c("ind","channel","value")
df2$cluster <- L[[2]]
df2$type <- factor(rep(ffchannel,each=dim(dat)[1]),levels=levels(ffchannel))

gg3 <- ggplot(df2, aes(x=value)) + 
    scale_colour_manual(values=ccol) + 
    #scale_x_continuous(limits=c(0,400)) +
    geom_histogram(aes(y=..density..,group=channel,colour=channel),bins=250) +
    geom_density(aes(group=channel),size=.5, color='black', alpha=0.5) +
    facet_grid(channel ~ cluster, scale='free') + 
    #guides(col=guide_legend(ncol=1))
    theme(strip.text.y=element_text(angle=0),
          plot.title=element_text(size=ts),
          axis.title.x=element_text(size=ts),
          axis.title.y=element_text(size=ts),
          legend.title=element_text(size=ts),
          legend.text=element_text(size=ts-2),
          strip.text=element_text(size=ts), 
          legend.position='none')








df2 <- melt(as.matrix(dat))
names(df2) <- c("ind","channel","value")
df2$cluster <- L[[2]]
df2$type <- factor(rep(ffchannel,each=dim(fs)[1]),levels=levels(ffchannel))

gg3 <- ggplot(df2[sample(dim(df2)[1],1e2),], 
              aes(x = as.factor(channel), y=value,
                  colour=channel)) + 
       scale_colour_manual(values=ccol) + 
       geom_point() 
print(gg3)
Figure 11: Kernel density estimates for each channel, on fs data given cluster from km++ level 2

5.4 Clusters and Spatial Location (Lv 2)

Using the location data and the results of K-means++ we show a 3d scatter plot colored according to cluster.

set.seed(2^12)
s1 <- sample(dim(loc)[1],5e4)

locs2 <- loc[s1,]
locs2$cluster <- L[[2]][s1]

YlOrBr <- c("#FFFFD4", "#FED98E", "#FE9929", "#D95F0E", "#993404")
col.pal <- colorRampPalette(YlOrBr)

plot3d(locs2$V1,locs2$V2,locs2$V3,
       #col=colorpanel(8,"brown","blue")[order(table(L[[2]]))][locs2$cluster],
       col=col.pal(8)[-seq(1,8,2)][order(table(L[[2]]))][locs2$cluster],
       alpha=0.75,
       xlab='x', 
       ylab='y', 
       zlab='z'
       )

subid <- currentSubscene3d()
rglwidget(elementId="plot3dLocationsLV2", height=720, width=720)

6 Level 3: K-means++ for \(K=2\).

6.1 Within cluster correlations (Lv 3)

corLV3 <- lapply(c(1:8),function(x){cor(dat[L[[3]] == x,])})

par(mfrow=c(3,2))
for(pl in corLV3){
corrplot(pl,method="color",tl.col=ccol[ford], tl.cex=0.8)
}
Figure 12: Within cluster correlations for level 3. (c111, c112, c121, c122, c211, c212, c221, c222)

Figure 12: Within cluster correlations for level 3. (c111, c112, c121, c122, c211, c212, c221, c222)

6.2 Heat maps (Lv 3):

## Formatting data for heatmap
aggp3 <- aggregate(dat,by=list(lab=L[[3]]),FUN=function(x){mean(x)})
aggp3 <- as.matrix(aggp3[,-1])
rownames(aggp3) <- clusterFraction(L[[3]])

The following are heatmaps generated from clustering via K-means++

heatmap.2(as.matrix(aggp3),dendrogram='row',Colv=NA,trace="none", col=mycol,colCol=ccol[ford],cexRow=0.8, keysize=1.25,symkey=FALSE,symbreaks=FALSE,scale="none", srtCol=90,main="Heatmap of `fs` data.") 
#  [1] "#197300"    "#197300"    "#197300"    "#197300"    "#197300"   
#  [6] "#5ed155"    "#5ed155"    "#5ed155"    "#5ed155"    "#5ed155"   
# [11] "#5ed155"    "#660000"    "#660000"    "#660000"    "#cc0000"   
# [16] "#cc0000"    "#cc0000"    "#ff9933"    "#ff9933"    "mediumblue"
# [21] "mediumblue" "mediumblue" "gold"       "gold"
Figure 13: Heatmap of the cluster means vs channels. Rows and columns are rearranged according to synapse type.

Percentage of data within cluster is presented on the right side of the heatmap.

6.3 Kernel Density Estimates of the marginals | cluster (Lv 3)

Here we look at the kernel density estimates within each cluster to compare.

df3 <- melt(as.matrix(dat))
names(df3) <- c("ind","channel","value")
df3$cluster <- L[[3]]
df3$type <- factor(rep(ffchannel,each=dim(dat)[1]),levels=levels(ffchannel))

gg4 <- ggplot(df3, aes(x=value)) + 
    scale_colour_manual(values=ccol) + 
    #scale_x_continuous(limits=c(0,400)) +
    geom_histogram(aes(y=..density..,group=channel,colour=channel),bins=250) +
    geom_density(aes(group=channel),size=.5, color='black', alpha=0.5) +
    facet_grid(channel ~ cluster, scale='free') + 
    #guides(col=guide_legend(ncol=1)) + 
    theme(strip.text.y=element_text(angle=0),
          plot.title=element_text(size=ts),
          axis.title.x=element_text(size=ts),
          axis.title.y=element_text(size=ts),
          legend.title=element_text(size=ts),
          legend.text=element_text(size=ts-2),
          strip.text=element_text(size=ts), 
          legend.position='none')
print(gg4)
Figure 14: Kernel density estimates for each channel, on fs data given cluster from km++ level 3

6.4 Clusters and Spatial Location (Lv 3)

Using the location data and the results of K-means++ we show a 3d scatter plot colored according to cluster.

set.seed(2^12)
s1 <- sample(dim(loc)[1],5e4)

locs3 <- loc[s1,]
locs3$cluster <- L[[3]][s1]

plot3d(locs3$V1,locs3$V2,locs3$V3,
       col=col.pal(16)[-seq(1,8,2)][order(table(L[[3]]))][locs3$cluster],
       alpha=0.65,
       xlab='x', 
       ylab='y', 
       zlab='z'
       )

subid <- currentSubscene3d()
rglwidget(elementId="plot3dLocationsLV3", height=720, width=720)